from typing import Optional

from pydantic import BaseModel, ConfigDict, EmailStr
from pydantic.types import UUID4

from app.models.user import Provider, Role
from app.schemas.archivable import Archivable


# 共享属性
class UserBase(BaseModel):
    email: Optional[EmailStr] = "user@example.com"
    first_name: Optional[str] = "John"
    last_name: Optional[str] = "Doe"


# 通过API创建时接收的属性
class UserCreate(UserBase):
    email: EmailStr
    sso_provider_id: Optional[str] = None
    password: Optional[str] = None
    provider: Optional[Provider] = Provider.EMAIL


# 通过API更新时接收的属性
class UserUpdate(UserBase):
    pass


# 数据库中存储的属性
class UserInDBBase(UserBase, Archivable):
    model_config = ConfigDict(from_attributes=True)

    id: UUID4
    confirmed: Optional[bool]
    role: Role
    provider: Provider
    is_admin: bool
    is_moderator: bool
    is_customer: bool
    profile_picture_url: Optional[str]


# 通过API返回的属性
class User(UserInDBBase):
    pass


# 数据库中存储的属性（额外）
class UserInDB(UserInDBBase):
    full_name: Optional[str] = "John Doe"
    password_hash: str
